#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Simple testing framework validation
"""

import os
import json
from pathlib import Path
from datetime import datetime

def main():
    print("=" * 60)
    print("Testing Framework Validation Report")
    print("=" * 60)
    print(f"Validation time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")

    # Frontend tests validation
    print("\nFrontend Tests:")
    vitest_config = Path('endo_sight_uc_web/vitest.config.ts').exists()
    test_files = list(Path('endo_sight_uc_web/tests').glob('**/*.spec.ts'))
    setup_file = Path('endo_sight_uc_web/tests/setup.ts').exists()

    print(f"  Vitest config: {'OK' if vitest_config else 'MISSING'}")
    print(f"  Test files: {len(test_files)} found")
    print(f"  Setup file: {'OK' if setup_file else 'MISSING'}")

    # Backend tests validation
    print("\nBackend Tests:")
    package_json = Path('endo_sight_uc_server/package.json')
    jest_config = False
    if package_json.exists():
        with open(package_json, 'r') as f:
            data = json.load(f)
            jest_config = 'jest' in data

    test_files = list(Path('endo_sight_uc_server/tests').glob('**/*.test.js'))
    setup_file = Path('endo_sight_uc_server/tests/setup.js').exists()
    babel_config = Path('endo_sight_uc_server/babel.config.json').exists()

    print(f"  Jest config: {'OK' if jest_config else 'MISSING'}")
    print(f"  Test files: {len(test_files)} found")
    print(f"  Setup file: {'OK' if setup_file else 'MISSING'}")
    print(f"  Babel config: {'OK' if babel_config else 'MISSING'}")

    # AI tests validation
    print("\nAI Service Tests:")
    test_files = list(Path('endo_sight_uc_ai').glob('**/test*.py'))
    req_files = list(Path('endo_sight_uc_ai').glob('requirements*.txt'))

    print(f"  Test files: {len(test_files)} found")
    print(f"  Requirements files: {len(req_files)} found")

    # E2E tests validation
    print("\nE2E Tests:")
    playwright_config = Path('endo_sight_uc_web/playwright.config.ts').exists()
    e2e_test_files = list(Path('endo_sight_uc_web/tests-e2e').glob('**/*.spec.ts'))
    e2e_test_files.extend(list(Path('tests').glob('**/*.spec.ts')))

    print(f"  Playwright config: {'OK' if playwright_config else 'MISSING'}")
    print(f"  E2E test files: {len(e2e_test_files)} found")

    # Infrastructure files
    print("\nInfrastructure:")
    ci_cd = Path('.github/workflows/ci-cd.yml').exists()
    monitoring = Path('monitoring/dashboard.html').exists()
    report_gen = Path('scripts/generate-test-report.js').exists()

    print(f"  CI/CD pipeline: {'OK' if ci_cd else 'MISSING'}")
    print(f"  Monitoring dashboard: {'OK' if monitoring else 'MISSING'}")
    print(f"  Report generator: {'OK' if report_gen else 'MISSING'}")

    print("\n" + "=" * 60)
    print("Validation Summary:")

    total_checks = 0
    passed_checks = 0

    checks = [
        ("Frontend Vitest config", vitest_config),
        ("Frontend setup file", setup_file),
        ("Backend Jest config", jest_config),
        ("Backend Babel config", babel_config),
        ("Backend setup file", Path('endo_sight_uc_server/tests/setup.js').exists()),
        ("AI requirements files", len(req_files) > 0),
        ("E2E Playwright config", playwright_config),
        ("CI/CD pipeline", ci_cd),
        ("Monitoring dashboard", monitoring),
        ("Report generator", report_gen)
    ]

    for name, passed in checks:
        total_checks += 1
        if passed:
            passed_checks += 1
            print(f"  [PASS] {name}")
        else:
            print(f"  [FAIL] {name}")

    percentage = (passed_checks / total_checks) * 100 if total_checks > 0 else 0
    print(f"\nOverall Score: {passed_checks}/{total_checks} ({percentage:.1f}%)")

    if percentage >= 80:
        print("Status: EXCELLENT")
    elif percentage >= 60:
        print("Status: GOOD")
    elif percentage >= 40:
        print("Status: NEEDS WORK")
    else:
        print("Status: POOR")

    print("=" * 60)

if __name__ == "__main__":
    main()